package main

import "fmt"

// 自己实现的链表
/****************************************/
/**
	head := NewListNode([]int{1, 2, 3})
	printLinkedList(head)
 */

type ListNode struct {
	Val  int
	Next *ListNode
}

func NewListNode(nums []int) *ListNode {
	return createLinkedList(nums)
}

func createLinkedList(nums []int) *ListNode {

	if len(nums) == 0 { return nil }

	head := &ListNode{ Val: nums[0] }
	
	cur := head
	for i := 1; i < len(nums); i++ {
		cur.Next = &ListNode{ Val: nums[i] }
		cur = cur.Next
	}
	
	return head
}

func printLinkedList(head *ListNode) {

	cur := head
	for cur != nil {
		fmt.Print(cur.Val, "->")
		cur = cur.Next
	}
	fmt.Println("NULL")
}
/****************************************/

func main() {

	head := NewListNode([]int{1, 2, 3})
	printLinkedList(head)
}
